﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.system.attend
{
    public partial class holiday_edit : ModulePage 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int holidayId = (Request.QueryString["holiday_id"] == null) ? 0 : int.Parse(Request.QueryString["holiday_id"].ToString());
                this.ViewState["HolidayId"] = holidayId;
                DataTable table = new AttendHolidayDao().SelectByHolidayId(base.Conn, holidayId);
                if (table.Rows.Count > 0)
                {
                    this.txtBeginDate.Value = Convert.ToDateTime(table.Rows[0]["BeginDate"].ToString()).ToString("d");
                    this.txtEndDate.Value = Convert.ToDateTime(table.Rows[0]["EndDate"].ToString()).ToString("d");
                }
            }
            if (this.Page.IsPostBack)
            {
                AttendHolidayDao dao = new AttendHolidayDao();
                AttendHolidayData data = new AttendHolidayData();
                data.HolidayId = Convert.ToInt32(this.ViewState["HolidayId"].ToString());
                data.BeginDate = Convert.ToDateTime(this.txtBeginDate.Value);
                data.EndDate = Convert.ToDateTime(this.txtEndDate.Value);
                dao.Update(base.Conn, data);
                base.CloseConn();
                Response.Redirect("holiday.aspx");
            }
        }
 

    }
}
